{% extends base_template %}
{# Copyright The IETF Trust 2015-2020, All Rights Reserved #}
{% load origin %}
{% load django_bootstrap5 person_filters %}
{% load nomcom_tags %}
{% block subtitle %}- Feedback{% endblock %}
{% block nomcom_content %}
    {% origin %}
    <p id="instructions" class="alert alert-info my-3">
        {% if nomcom.group.state_id == 'conclude' %}
            Feedback to this NomCom is closed.
        {% elif positions|length != 0 and topics|length != 0 %}
            Select a nominee or topic from the list on the right to obtain a new feedback form.
        {% elif positions|length != 0 %}
            Select a nominee from the list on the right to obtain a new feedback form.
        {% elif topics|length != 0 %}
            Select a topic from the list on the right to obtain a new feedback form.
        {% else %}
            This NomCom is not accepting feedback at this time.
        {% endif %}
    </p>
    {% if nomcom|has_publickey %}
        <div class="row">
            <div id="nominees" class="col-sm-2 order-last">
                {% if positions|length != 0 %}
                <h2 class="navskip mt-4">Nominees</h2>
                <p>
                    A number after a name indicates
                    that you have given comments on this nominee
                    earlier. Position the mouse pointer over
                    the button for more information about this
                    nominee.
                </p>
                {% for p in positions %}
                    {% if p.nomineeposition_set.accepted.not_duplicated %}
                        <h3 class="navskip mt-3">{{ p.name }}</h3>
                        <div class="d-grid gap-3">
                            {% for np in p.nomineeposition_set.accepted.not_duplicated %}
                                <a class="btn btn-primary btn-sm position-relative"
                                   {% if nomcom.group.state_id != 'conclude' %}href="?nominee={{ np.nominee.id }}&amp;position={{ np.position.id }}"{% endif %}
                                    {% with count=counts|lookup:np.position.id|lookup:np.nominee.id|default:0 %}
                                       title="{% if count %}{{ count }} earlier comment{{ count|pluralize }} from you {% else %}You have not yet provided feedback {% endif %} on {{ np.nominee.email.address }} as {{ np.position }}">
                                        {{ np.nominee.name }}
                                        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill {% if count %}text-bg-success{% else %}text-bg-danger{% endif %}">
                                            {{ count }}
                                        </span>
                                    {% endwith %}
                                </a>
                            {% endfor %}
                        </div>
                    {% endif %}
                {% endfor %}
                {% endif %}
                {% if topics|length != 0 %}
                <h2 class="navskip mt-4">Topics</h2>
                <div class="d-grid gap-3">
                    {% for t in topics %}
                        <a class="btn btn-primary btn-sm position-relative"
                           {% if nomcom.group.state_id != 'conclude' %}href="?topic={{ t.id }}"{% endif %}
                           title="{% if count %}{{ count }} earlier comment{{ count|pluralize }} from you {% else %}You have not yet provided feedback {% endif %} on {{ t.subject }}">
                            {{ t.subject }}
                            {% with count=topic_counts|lookup:t.id|default:0 %}
                                <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill {% if count %}text-bg-success{% else %}text-bg-danger{% endif %}">
                                    {{ count }}
                                </span>
                            {% endwith %}
                        </a>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
            <div class="col-sm-10">
                {% if form %}
                    {% if form.position %}
                        {% if nomcom.show_nominee_pictures and form.nominee.email.person.photo_thumb %}
                            <div class="float-end ms-4 my-4">{% include "person/photo.html" with person=form.nominee.person  %}</div>
                        {% endif %}
                        <h2 class="navskip mt-4">
                            Provide feedback
                            <br>
                            <small class="text-body-secondary">{{ form.nominee.email.person.name }} for {{ form.position.name }}</small>
                        </h2>
                        <p class="mt-3">
                            Provide feedback about {% person_link form.nominee.person with_email=False %}
                            for the <b>{{ form.position.name }}</b> position.
                        </p>
                    {% elif form.topic %}
                        <h2 >
                            Provide feedback
                            <br>
                            <small class="text-body-secondary">{{ form.topic.subject }}</small>
                        </h2>
                        <div class="card my-3">
                            <div class="card-header">Description: {{ form.topic.subject }}</div>
                            <div class="card-body">{{ form.topic.get_description|safe }}</div>
                        </div>
                    {% endif %}
                    <p>
                        This feedback will only be available to
                        <a href="{% url 'ietf.nomcom.views.year_index' year=year %}">the current NomCom</a>.
                        You can have the feedback mailed back to you by selecting the option below.
                    </p>
                    <form class="float-start" id="feedbackform" method="post">
                        {% csrf_token %}
                        {% bootstrap_form form %}
                        <button class="btn btn-primary" type="submit" name="save">Save</button>
                    </form>
                {% endif %}
            </div>
        </div>
    {% endif %}
{% endblock %}